using System;
using System.Collections.Generic;
using System.Text;

namespace TidhiGanitam.DataModel
{
    public class Varam: DegreeEntity
    {
        #region properties
        public double Vaaram
        {
            get
            {
                double dVaram = MathHelper.GetDegrees(dDegrees);
                return dVaram % 7;
            }
        }
        public double Ghadiyalu
        {
            get
            {
                return MathHelper.GetMinutes(dDegrees);
            }
        }
        public double Vighadiyalu
        {
            get
            {
                return MathHelper.GetSeconds(dDegrees);
            }
        }
        public double RawValue
        {
            get { return dDegrees; }
        }
        public override string ToString()
        {
            string sRetString = string.Empty;
            sRetString = string.Format("{0}-{1}-{2}", Vaaram.ToString(),
                                                    Ghadiyalu.ToString(),
                                                    Vighadiyalu.ToString());
            return sRetString;
        }

        #endregion

        public Varam()
            :base()
        { 
        }
        public Varam(Varam varam)
            :base((DegreeEntity)varam)
        {
        }
        public Varam(double tidhi, double ghadiyalu, double vighadiyalu)
            :base(tidhi, ghadiyalu, vighadiyalu,0)
        {
        }
        public Varam(double tidhi, double ghadiyalu)
            :base(tidhi, ghadiyalu, 0, 0)
        {
        }
        public Varam(double tidhi)
            :base(tidhi)
        {
        }

        #region operator overloading routines

        public static Varam operator +(Varam op1, Varam op2)
        {
            Varam RetVal = new Varam();
            RetVal.dDegrees = op1.dDegrees + op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator +(Varam op1, double op2)
        {
            Varam RetVal = new Varam();
            RetVal.dDegrees = op1.dDegrees + op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator -(Varam op1, Varam op2)
        {
            Varam RetVal = new Varam();
            if (op1 < op2)
            {
                op1.dDegrees += 7f;
            }
            RetVal.dDegrees = op1.dDegrees - op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator -(Varam op1, double op2)
        {
            Varam RetVal = new Varam();
            if (op1.dDegrees < op2)
            {
                op1.dDegrees += 7F;
            }
            RetVal.dDegrees = op1.dDegrees - op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator *(Varam op1, Varam op2)
        {
            Varam RetVal = new Varam();
            RetVal.dDegrees = op1.dDegrees * op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator *(Varam op1, double op2)
        {
            Varam RetVal = new Varam();
            RetVal.dDegrees = op1.dDegrees * op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator /(Varam op1, Varam op2)
        {
            Varam RetVal = new Varam();
            if (op2.dDegrees != 0)
            {
                RetVal.dDegrees = op1.dDegrees / op2.dDegrees;
            }
            RetVal.Refresh();
            return RetVal;
        }
        public static Varam operator /(Varam op1, double op2)
        {
            Varam RetVal = new Varam();
            if (op2 != 0)
            {
                RetVal.dDegrees = op1.dDegrees / op2;
            }
            RetVal.Refresh();
            return RetVal;
        }
        public static bool operator >(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees > op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator >=(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees >= op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator ==(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees == op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator <(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees < op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator <=(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees < op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator !=(Varam op1, Varam op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees != op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion

        public void Refresh()
        {
            this.dDegrees = dDegrees % 7;
        }

    }
}
